/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.persistence.SequenceGenerator;
import javax.persistence.GeneratedValue;

/**
 *
 * @author Samy.A.Omar
 */
@Entity
@Table(name = "GROUPS")
@NamedQueries({
    @NamedQuery(name = "Group.findAll", query = "SELECT g FROM Group g"),
    @NamedQuery(name = "Group.findByGroupId", query = "SELECT g FROM Group g WHERE g.groupId = :groupId"),
    @NamedQuery(name = "Group.findByGroupName", query = "SELECT g FROM Group g WHERE g.groupName = :groupName")})

public class Group implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    
  
    @Column(name = "GROUP_ID")
    @SequenceGenerator(name="Group_Gen", sequenceName="GROUPS_SEQ")
    @Id 
    @GeneratedValue(generator="Group_Gen")
    private Integer groupId;
    
    @NotNull(message="Group name must be specified")
    @Size(max = 20)
    @Column(name = "GROUP_NAME")
    private String groupName;
    
    @OneToMany(mappedBy = "group", fetch = FetchType.LAZY,cascade=CascadeType.PERSIST)
    private Collection<User> userCollection;
    
    
    @OneToMany(mappedBy = "assignedGroup", fetch = FetchType.LAZY,cascade=CascadeType.PERSIST)
    private Collection<Ticket> assignedTicckets;
    
    
    

    public Integer getGroupId() {
		return groupId;
	}



	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}



	public Collection<User> getUserCollection() {
		return userCollection;
	}



	public void setUserCollection(Collection<User> userCollection) {
		this.userCollection = userCollection;
	}


	public Collection<Ticket> getAssignedTicckets() {
		return assignedTicckets;
	}



	public void setAssignedTicckets(Collection<Ticket> assignedTicckets) {
		this.assignedTicckets = assignedTicckets;
	}



	public Group() {
    }

 

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (groupId != null ? groupId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Group)) {
            return false;
        }
        Group other = (Group) object;
        if ((this.groupId == null && other.groupId != null) || (this.groupId != null && !this.groupId.equals(other.groupId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        //return "model.entities.Group[ groupId=" + groupId + " ]";
       	return getGroupId() + "" ;
    }
    
}
